package com.usian.residentialquarters.controller;

import com.usian.commom.pojo.ResidentialQuarters;
import com.usian.commom.vo.ResultCommonVo;
import com.usian.residentialquarters.service.ResidentialQuartersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @TODO:
 * @Author:baimu
 * @Date:2023 11 30 14 02
 **/

@RestController
@RequestMapping("residentialquarters")
//@CrossOrigin(origins="*")
public class ResidentialQuartersController {


    @Autowired
    ResidentialQuartersService residentialQuartersService;

    @PostMapping("/findResidentialQuartersPage")
    public ResultCommonVo findResidentialQuartersPage(@RequestBody ResidentialQuarters residentialQuarters,
                                                      @RequestParam(value = "page",defaultValue = "1") Integer page,
                                                      @RequestParam(value = "size",defaultValue = "10")Integer size){

        return residentialQuartersService.findResidentialQuartersPage(residentialQuarters, page, size);

    }

    @GetMapping("/findResidentialQuartersById/{id}")
    public ResultCommonVo findResidentialQuartersById(@PathVariable Integer id){

        ResidentialQuarters residentialQuarters = residentialQuartersService.getById(id);

        return ResultCommonVo.success(residentialQuarters);
    }


    @PostMapping("/updateResidentialQuarters")
    public ResultCommonVo updateResidentialQuarters(@RequestBody ResidentialQuarters residentialQuarters){
        boolean b = residentialQuartersService.updateById(residentialQuarters);
        return ResultCommonVo.success(b);
    }



    @GetMapping("/delResidentialQuarters/{id}")
    public ResultCommonVo delResidentialQuarters(@PathVariable Integer id){
        boolean b = residentialQuartersService.removeById(id);
        return ResultCommonVo.success(b);
    }


@PostMapping("/saveResidentialQuarters")
    public ResultCommonVo saveResidentialQuarters(@RequestBody ResidentialQuarters residentialQuarters){
        boolean save = residentialQuartersService.save(residentialQuarters);
        return ResultCommonVo.success(save);
    }



}
